package com.rain.cy.framework.utils;

import com.qiniu.common.Zone;
import com.qiniu.storage.Configuration;
import com.qiniu.util.Auth;
import com.qiniu.util.StringMap;
import com.rain.cy.framework.constant.QiNiuConstant;
import lombok.extern.slf4j.Slf4j;

/**
 * 七牛云相关操作工具类
 *
 * @author yu_chen
 * @date 2018年4月2日17:02:07
 */
@Slf4j
public class QiniuOperateUtil {
    /**
     * 索引文件名称
     */
    private static final Auth AUTH = Auth.create(QiNiuConstant.ACCESS_KEY,
            QiNiuConstant.SECRET_KEY);
    private static final Configuration cfg = new Configuration(Zone.zone0());

    /**
     * 获取公共空间上传token
     *
     * @return
     */
    public static String getUploadToken() {
        return AUTH
                .uploadToken(
                        QiNiuConstant.OPEN_BUCKET,
                        null,
                        3600 * 24,
                        new StringMap()
                                .putNotEmpty(
                                        "returnBody",
                                        "{\"key\": $(key), \"hash\": $(etag), \"width\": $(imageInfo.width), \"height\": $(imageInfo.height)}"));
    }



}
